﻿using System;
using System.Text;
using System.Net;
using System.Net.Sockets;

namespace MouseAndCat.Model
{
    internal class Listener
    {
        public delegate void DataReceivedHandler(byte[] Data);
        //public event DataReceivedHandler DataReceived;

        private static UdpClient _udp;
        //private static DataReceivedHandler _handler;
        //private bool _listen = true;
        private IPEndPoint _endPoint;

        public Listener(IPAddress remoteIp, int port)
        {
            _endPoint = new IPEndPoint(remoteIp, port);
            _udp = new UdpClient(_endPoint);
        }

        public void Listen()
        {
            byte[] data = _udp.Receive(ref _endPoint);
            System.Diagnostics.Debug.WriteLine("Data received: {0}", Encoding.ASCII.GetString(data));
        }
    }
}
